package com.yawn.zerodefect.controller;

import com.yawn.zerodefect.controller.entity.RestResponse;
import com.yawn.zerodefect.entity.Defect;
import com.yawn.zerodefect.service.DefectService;
import com.yawn.zerodefect.util.WebUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @author Created by yawn on 2018-01-30 17:42
 */
@RestController
public class DefectController {

    @Resource
    private DefectService defectService;

    @PostMapping("/defect/start")
    public RestResponse startDefect(@RequestBody Defect defect, HttpSession session) {
        return defectService.startDefect(WebUtil.getUser(session),defect);
    }

    @GetMapping("/task/todo")
    public RestResponse todoTask(HttpSession session) {
        return defectService.todoTask(WebUtil.getUser(session));
    }

    @PostMapping("/set/assignee")
    public RestResponse setAssignee(@RequestBody Defect defect, HttpSession session) {
        return defectService.setAssignee(WebUtil.getUser(session), defect);
    }

    @PostMapping("/do/task")
    public RestResponse doTask(@RequestBody Defect defect, HttpSession session) {
        return defectService.doTask(WebUtil.getUser(session), defect);
    }

    @PostMapping("/defect/revise")
    public RestResponse reviseDefect(@RequestBody Defect defect, HttpSession session) {
        return defectService.reviseDefect(WebUtil.getUser(session), defect);
    }

    @PostMapping("/comment/add")
    public RestResponse addComment(HttpSession session, String taskId, String comment) {
        return defectService.addComment(WebUtil.getUser(session), taskId, comment);
    }

    @GetMapping("/comment/list")
    public RestResponse getComment(String taskId) {
        return defectService.getProcessInstanceComment(taskId);
    }

}

